#include <iostream>
#include <unistd.h>
#include <mutex>

#include <gtest/gtest.h>
#include <boost/thread.hpp>
#include <boost/progress.hpp>
#include <libgo/coroutine.h>

#define O(x) std::cout << x << std::endl

namespace nmutex {

    static co_mutex g_mutex;
    static const int co_count = 100;
    static const int switch_per_co = 10;
    static const int thread_count = 4;
    int g_int = 0;

    void foo() {
        //std::unique_lock<co_mutex> lk(g_mutex);
        for (int i = 0; i < switch_per_co; ++i) {
            std::unique_lock<co_mutex> lk(g_mutex);
            O(++g_int);
        }
    }

}

TEST(nmutex, test) {
    using namespace nmutex;

    for (int i = 0; i < co_count; ++i) {
        go foo;
    }

    {
        boost::progress_timer pt;
        co_sched.Start();
        O(thread_count << " threads, run " << co_count << " coroutines, " << co_count * switch_per_co << " times switch");
    }
}
